clear
ssc install estout, replace

*group level summary results
{
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"

* group level outcomes table
collapse (mean) ifmontwentyfivebacrossrounds ifmonninetybacrossrounds totaldecisionnumbersacrossrounds group_target_10 numberoftimesindividualmonitored, by(setting monitoring)

clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"

* group level outcomes table
collapse (mean) ifmontwentyfivebacrossrounds ifmonninetybacrossrounds totaldecisionnumbersacrossrounds group_target_10 numberoftimesindividualmonitored, by(setting monitoring ninety seq)

clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"

* group level outcomes table
collapse (sd) ifmontwentyfivebacrossrounds ifmonninetybacrossrounds totaldecisionnumbersacrossrounds group_target_10 numberoftimesindividualmonitored, by(setting monitoring)

clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"

* group level outcomes table
collapse (sd) ifmontwentyfivebacrossrounds ifmonninetybacrossrounds totaldecisionnumbersacrossrounds group_target_10 numberoftimesindividualmonitored, by(setting monitoring ninety seq)
}

*group level rank sum tests
{
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"	

*result 1
tabstat totaldecisionnumbersacrossrounds ifmontwentyfivebacrossrounds ifmonninetybacrossrounds if setting == "Bonus", by(monitoring) statistics(median) 

ranksum totaldecisionnumbersacrossrounds if setting == "Bonus", by(monitoring) 
ranksum ifmontwentyfivebacrossrounds if setting == "Bonus", by(monitoring) 
ranksum ifmonninetybacrossrounds if setting == "Bonus", by(monitoring) 

*result 1 robustness
tabstat totaldecisionnumbersacrossrounds ifmonninetybacrossrounds ifmontwentyfivebacrossrounds if setting == "Fine", by(monitoring) statistics(median) 


clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\250217 session level welfare.csv"	
ranksum totaldecisionnumbersacrossrounds if setting == "Fine", by(monitoring) 
ranksum ifmontwentyfivebacrossrounds if setting == "Fine", by(monitoring) 
ranksum ifmonninetybacrossrounds if setting == "Fine", by(monitoring) 

clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"	
* result 2
generate pigou_diff_twentyfive = ifmontwentyfivebacrossrounds-ben_pigou_25_uc
generate pigou_diff_ninety = ifmonninetybacrossrounds-ben_pigou_90_uc

estpost tabstat ///
 pigou_diff_twentyfive pigou_diff_ninety, ///
 c(stat) stat(median) by(setting)


 esttab using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\pigou_welfare_differences.tex", replace ////
 cells("p50") nonumber ///
  nomtitle nonote noobs label booktabs ///
  collabels("Median")

signrank pigou_diff_twentyfive = 0 if setting == "Bonus" & monitoring == 1
signrank pigou_diff_ninety = 0 if setting == "Bonus" & monitoring == 1


tabstat pigou_diff_twentyfive if ninety == 0, c(stat) stat(median) by(setting)
signrank pigou_diff_twentyfive = 0 if setting == "Bonus" & monitoring == 1 & ninety == 0

tabstat pigou_diff_ninety if ninety == 1, c(stat) stat(median) by(setting)
signrank pigou_diff_ninety = 0 if setting == "Bonus" & monitoring == 1 & ninety == 1
signrank pigou_diff_ninety = 0 if setting == "Fine" & monitoring == 1 & ninety == 1

clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\250217 session level welfare.csv"	
signrank pigou_diff_twentyfive = 0 if setting == "Fine" & monitoring == 1
signrank pigou_diff_ninety = 0 if setting == "Fine" & monitoring == 1
signrank pigou_diff_twentyfive = 0 if setting == "Fine" & monitoring == 1 & ninety == 0
signrank pigou_diff_ninety = 0 if setting == "Fine" & monitoring == 1 & ninety == 1


* result 3
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219 group level outcomes of interest.csv"	
tabstat numberoftimesindividualmonitored totaldecisionnumbersacrossrounds ifmontwentyfivebacrossrounds ifmonninetybacrossrounds if setting == "Bonus" & monitoring == 1, by(ninety) statistics(median)

ranksum numberoftimesindividualmonitored if setting == "Bonus" & monitoring == 1, by(ninety) 
ranksum totaldecisionnumbersacrossrounds if setting == "Bonus" & monitoring == 1, by(ninety)
ranksum ifmontwentyfivebacrossrounds if setting == "Bonus" & monitoring == 1, by(ninety)
ranksum ifmonninetybacrossrounds if setting == "Bonus" & monitoring == 1, by(ninety)

*result 3 robustness
tabstat numberoftimesindividualmonitored totaldecisionnumbersacrossrounds ifmontwentyfivebacrossrounds if setting == "Fine" & monitoring == 1, by(ninety) statistics(median)

ranksum numberoftimesindividualmonitored if setting == "Fine" & monitoring == 1, by(ninety) 
ranksum totaldecisionnumbersacrossrounds if setting == "Fine" & monitoring == 1, by(ninety)
ranksum ifmontwentyfivebacrossrounds if setting == "Fine" & monitoring == 1, by(ninety)

* result 4
tabstat totaldecisionnumbersacrossrounds numberoftimesindividualmonitored ifmontwentyfivebacrossrounds ifmonninetybacrossrounds if setting == "Bonus" & monitoring == 1, by(seq) statistics(median)

ranksum totaldecisionnumbersacrossrounds if setting == "Bonus" & monitoring == 1, by(seq)
ranksum numberoftimesindividualmonitored if setting == "Bonus" & monitoring == 1, by(seq)
ranksum ifmontwentyfivebacrossrounds if setting == "Bonus" & monitoring == 1, by(seq)
ranksum ifmonninetybacrossrounds if setting == "Bonus" & monitoring == 1, by(seq)

* result 4 robustness
tabstat totaldecisionnumbersacrossrounds numberoftimesindividualmonitored ifmontwentyfivebacrossrounds ifmonninetybacrossrounds if setting == "Fine" & monitoring == 1, by(seq) statistics(median)

ranksum totaldecisionnumbersacrossrounds if setting == "Fine" & monitoring == 1, by(seq)
ranksum numberoftimesindividualmonitored if setting == "Fine" & monitoring == 1, by(seq)
ranksum ifmontwentyfivebacrossrounds if setting == "Fine" & monitoring == 1, by(seq)
ranksum ifmonninetybacrossrounds if setting == "Fine" & monitoring == 1, by(seq)

 

	
}

*initial main text table on individual outcomes for first round
{
	clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219_All_data_lab_games_stata.csv"
gen ind_target = 0
replace ind_target = 1 if dn_applied==5
gen pigou_diff_twentyfive = ifmontwentyfive - 4.8
gen pigou_diff_ninety = ifmonninety - 4.15

lab var dn_applied "Pollution"
lab var ind_target "Target"
lab var monitoring_decision "Monitoring"
lab var	ifmontwentyfive "Welfare 0.25"
lab var	ifmonninety "Welfare 0.90"

lab var monitoring "Hybrid"
lab var ninety "High"
lab var seq "Seq"
lab var	actual_period "Round"

*individual level outcomes for first round only
est clear
eststo: reg dn_applied i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1, robust
eststo: reg ind_target i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1, robust
eststo: reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1, robust
eststo: reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1, robust
eststo: reg ifmonninety i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1, robust

eststo: reg dn_applied i.monitoring i.ninety##i.seq if fine == 0, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ind_target i.monitoring i.ninety##i.seq if fine == 0 , cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 0 , cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 0 , cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ifmonninety i.monitoring i.ninety##i.seq if fine == 0 , cl(unique_group_6)
estadd scalar Clusters = e(N_clust)


esttab using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\ind_first_bonus.tex", replace   ///
 b(3) se(3) sfmt(%9.0fc) noconstant  Clusters r2 label star(* 0.10 ** 0.05 *** 0.01) nobaselevels interaction(" $\times$ ")style(tex)   /// 
 booktabs nonotes
}

*appendix table for fine results
{
	clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219_All_data_lab_games_stata.csv"
gen ind_target = 0
replace ind_target = 1 if dn_applied==5
gen pigou_diff_twentyfive = ifmontwentyfive - 4.8
gen pigou_diff_ninety = ifmonninety - 4.15

lab var dn_applied "Pollution"
lab var ind_target "Target"
lab var monitoring_decision "Monitoring"
lab var	ifmontwentyfive "Welfare 0.25"
lab var	ifmonninety "Welfare 0.90"

lab var monitoring "Hybrid"
lab var ninety "High"
lab var seq "Seq"
lab var	actual_period "Round"

*individual level outcomes for first round and all ten rounds
est clear
eststo m1: wildbootstrap reg dn_applied i.monitoring i.ninety##i.seq if fine == 1 & actual_period == 11, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m1
}
estadd scalar Clusters = e(N_clust): m1
estadd scalar Rsq = e(r2): m1

eststo m2: wildbootstrap reg ind_target i.monitoring i.ninety##i.seq if fine == 1 & actual_period == 11, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m2
}
estadd scalar Clusters = e(N_clust): m2
estadd scalar Rsq = e(r2): m2

eststo m3: wildbootstrap reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 1 & actual_period == 11, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m3
}
estadd scalar Clusters = e(N_clust): m3
estadd scalar Rsq = e(r2): m3

eststo m4: wildbootstrap reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 1 & actual_period == 11, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m4
}
estadd scalar Clusters = e(N_clust): m4
estadd scalar Rsq = e(r2): m4

eststo m5: wildbootstrap reg ifmonninety i.monitoring i.ninety##i.seq if fine == 1 & actual_period == 11, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m5
}
estadd scalar Clusters = e(N_clust): m5
estadd scalar Rsq = e(r2): m5

eststo m6: wildbootstrap reg dn_applied i.monitoring i.ninety##i.seq if fine == 1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m6
}
estadd scalar Clusters = e(N_clust): m6
estadd scalar Rsq = e(r2): m6

eststo m7: wildbootstrap reg ind_target i.monitoring i.ninety##i.seq if fine == 1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m7
}
estadd scalar Clusters = e(N_clust): m7
estadd scalar Rsq = e(r2): m7

eststo m8: wildbootstrap reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m8
}
estadd scalar Clusters = e(N_clust): m8
estadd scalar Rsq = e(r2): m8

eststo m9: wildbootstrap reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m9
}
estadd scalar Clusters = e(N_clust): m9
estadd scalar Rsq = e(r2): m9

eststo m10: wildbootstrap reg ifmonninety i.monitoring i.ninety##i.seq if fine == 1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 
    estadd mat boot`stat'= boot`stat': m10
}
estadd scalar Clusters = e(N_clust): m10
estadd scalar Rsq = e(r2): m10


esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\ind_first_fine.tex", replace cells(b(star pvalue(bootp) fmt(3)) bootll(par("["))&bootul(par(","))&bootend(par("]"))) scalar(Clusters Rsq) ///
substitute (" ]1.000" "]") label collab(none) nonumb drop(_cons) ///
starlevels( * 0.10 ** 0.05 *** 0.010)

*appendix table for impact of fine framing
est clear
eststo m1: wildbootstrap reg dn_applied i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 1.fine 1.monitoring#1.fine actual_period 1.monitoring#c.actual_period
    estadd mat boot`stat'= boot`stat': m1
}
estadd scalar Clusters = e(N_clust): m1
estadd scalar Rsq = e(r2): m1

eststo m2: wildbootstrap reg ind_target i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 1.fine 1.monitoring#1.fine actual_period 1.monitoring#c.actual_period
    estadd mat boot`stat'= boot`stat': m2
}
estadd scalar Clusters = e(N_clust): m2
estadd scalar Rsq = e(r2): m2

eststo m3: wildbootstrap reg monitoring_decision i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 1.fine 1.monitoring#1.fine actual_period 1.monitoring#c.actual_period
    estadd mat boot`stat'= boot`stat': m3
}
estadd scalar Clusters = e(N_clust): m3
estadd scalar Rsq = e(r2): m3

eststo m4: wildbootstrap reg ifmontwentyfive i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 1.fine 1.monitoring#1.fine actual_period 1.monitoring#c.actual_period
    estadd mat boot`stat'= boot`stat': m4
}
estadd scalar Clusters = e(N_clust): m4
estadd scalar Rsq = e(r2): m4

eststo m5: wildbootstrap reg ifmonninety i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= 1.monitoring 1.ninety 1.seq 1.ninety#1.seq 1.fine 1.monitoring#1.fine actual_period 1.monitoring#c.actual_period
    estadd mat boot`stat'= boot`stat': m5
}
estadd scalar Clusters = e(N_clust): m5
estadd scalar Rsq = e(r2): m5


esttab m1 m2 m3 m4 m5 using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\fine_impact.tex", replace cells(b(star pvalue(bootp) fmt(3)) bootll(par("["))&bootul(par(","))&bootend(par("]"))) scalar(Clusters Rsq) ///
substitute (" ]1.000" "]") label collab(none) nonumb drop(_cons) ///
starlevels( * 0.10 ** 0.05 *** 0.010)

est clear
eststo:reg dn_applied i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cl(unique_group_12)
estadd scalar Clusters = e(N_clust)
eststo:reg ind_target i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cl(unique_group_12)
estadd scalar Clusters = e(N_clust)
eststo:reg monitoring_decision i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cl(unique_group_12)
estadd scalar Clusters = e(N_clust)
eststo:reg ifmontwentyfive i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cl(unique_group_12)
estadd scalar Clusters = e(N_clust)
eststo:reg ifmonninety i.monitoring i.ninety##i.seq i.fine i.monitoring#i.fine c.actual_period i.monitoring#c.actual_period, cl(unique_group_12)
estadd scalar Clusters = e(N_clust)

}

*COMPARISON TO SPRAGGON
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219_All_data_lab_games_stata.csv"
*EFFICIENCY
*control - not used in text
mean spraggonefficiency025 if monitoring ==0 & fine ==0

*hybrid mechanism - depending on cost
mean spraggonefficiency025 if monitoring ==1
mean spraggonefficiency090 if monitoring ==1


*comprehension questions and tremble hand errors
{
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219_All_data_lab_games_stata.csv"

gen first_four_qs = right_pre_play_1 + right_pre_play_2 + right_pre_play_3 + right_pre_play_4
gen mon_and_less = 0
replace mon_and_less = 1 if monitoring_decision == 1 & dn_applied < 5
gen mon_and_more = 0
replace mon_and_more = 1 if monitoring_decision == 1 & dn_applied > 5
gen over_twenty = 0
replace over_twenty = 1 if monitoring_decision == 0 & dn_applied > 20


 *performance in the comprehension questions
est clear

estpost tabstat ///
 first_four_qs total_right if actual_period==1, ///
 c(stat) stat(mean sd median) by(type)

 esttab using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\comprehension.tex", replace ////
 cells("mean(fmt(%6.2fc)) sd(fmt(%6.2fc)) p50") nonumber ///
  nomtitle nonote noobs label booktabs ///
  collabels("Mean" "SD" "Median")

 *performance in the comprehension questions
est clear

estpost tabstat ///
 mon_and_less mon_and_more over_twenty if fine==0, ///
 c(stat) stat(mean) by(type)

 esttab using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\tremble_hand.tex", replace ////
 cells("mean(fmt(%6.2fc))") nonumber ///
  nomtitle nonote noobs label booktabs ///
  collabels("Mean")
  
  
}
 
*robustness to comprehension questions and tremble hand error mistakes
{
 	
	* first robustness to comprehension first 4
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219_All_data_lab_games_stata.csv"
gen ind_target = 0
replace ind_target = 1 if dn_applied==5
gen pigou_diff_twentyfive = ifmontwentyfive - 4.8
gen pigou_diff_ninety = ifmonninety - 4.15
gen first_four_qs = right_pre_play_1 + right_pre_play_2 + right_pre_play_3 + right_pre_play_4

lab var dn_applied "Pollution"
lab var ind_target "Target"
lab var monitoring_decision "Monitoring"
lab var	ifmontwentyfive "Welfare 0.25"
lab var	ifmonninety "Welfare 0.90"

lab var monitoring "Hybrid"
lab var ninety "High"
lab var seq "Seq"
lab var	actual_period "Round"


est clear
eststo: reg dn_applied i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & first_four_qs==4, robust
eststo: reg ind_target i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & first_four_qs==4, robust
eststo: reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & first_four_qs==4, robust
eststo: reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & first_four_qs==4, robust
eststo: reg ifmonninety i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & first_four_qs==4, robust

eststo: reg dn_applied i.monitoring i.ninety##i.seq if fine == 0 & first_four_qs==4, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ind_target i.monitoring i.ninety##i.seq if fine == 0 & first_four_qs==4, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 0 & first_four_qs==4, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 0 & first_four_qs==4, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ifmonninety i.monitoring i.ninety##i.seq if fine == 0 & first_four_qs==4, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)



esttab using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\ind_first_robust_comprehension.tex", replace   ///
 b(3) se(3) sfmt(%9.0fc) noconstant scalar(Clusters) r2 label star(* 0.10 ** 0.05 *** 0.01) nobaselevels interaction(" $\times$ ")style(tex)   /// 
 booktabs nonotes
 
 * second robustness to tremble hand errors
est clear
eststo: reg dn_applied i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & subject_makes_tremble_hand==0, robust
eststo: reg ind_target i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & subject_makes_tremble_hand==0, robust
eststo: reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & subject_makes_tremble_hand==0, robust
eststo: reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & subject_makes_tremble_hand==0, robust
eststo: reg ifmonninety i.monitoring i.ninety##i.seq if fine == 0 & actual_period == 1 & subject_makes_tremble_hand==0, robust

eststo: reg dn_applied i.monitoring i.ninety##i.seq if fine == 0 & subject_makes_tremble_hand==0, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ind_target i.monitoring i.ninety##i.seq if fine == 0 & subject_makes_tremble_hand==0, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg monitoring_decision i.monitoring i.ninety##i.seq if fine == 0 & subject_makes_tremble_hand==0, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ifmontwentyfive i.monitoring i.ninety##i.seq if fine == 0 & subject_makes_tremble_hand==0, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)
eststo: reg ifmonninety i.monitoring i.ninety##i.seq if fine == 0 & subject_makes_tremble_hand==0, cl(unique_group_6)
estadd scalar Clusters = e(N_clust)

esttab using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\ind_first_robust_trembles.tex", replace   ///
 b(3) se(3) sfmt(%9.0fc) noconstant scalar(Clusters) r2 label star(* 0.10 ** 0.05 *** 0.01) nobaselevels interaction(" $\times$ ")style(tex)   /// 
 booktabs nonotes
 
 
 }
 
*looking at the dynamics of what people choose (learning) including learning in fine setting
{
 		
clear
import delimited "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\181219_All_data_lab_games_stata.csv"
gen ind_target = 0
replace ind_target = 1 if dn_applied==5
gen pigou_diff_twentyfive = ifmontwentyfive - 4.8
gen pigou_diff_ninety = ifmonninety - 4.15

xtset unique_id actual_period 
*sets the variables in the panel structure
gen previous_group_DN = L.group_total_dn
gen previous_my_DN = L.dn_applied  
*creates the previous group target info
gen previous_not_me_DN = previous_group_DN - previous_my_DN
replace previous_not_me_DN = . if (actual_period == 11)
gen previous_others_on_target = 0  
replace previous_others_on_target = (previous_not_me_DN <= 25) if (actual_period > 1)
replace previous_others_on_target = . if (actual_period == 1)
replace previous_others_on_target = . if (actual_period == 11)


gen previous_group_monitor = L.how_many_others_monitored 
*creates the previous group target info

lab var dn_applied "Pollution"
lab var ind_target "Target"
lab var monitoring_decision "Monitoring"
lab var	ifmontwentyfive "Welfare"
lab var	ifmontwentyfive "Welfare 0.25"
lab var	ifmonninety "Welfare 0.90"

lab var monitoring "Hybrid"
lab var ninety "High"
lab var seq "Seq"
lab var	actual_period "Round"
lab var previous_others_on_target "Lagged whether other's met target"
lab var previous_group_monitor "Lagged other's monitoring"

*individual level outcomes
est clear
eststo m1: wildbootstrap regress dn_applied previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 0 & monitoring ==1, cluster(unique_group_6) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m1
}
estadd scalar Clusters = e(N_clust): m1
estadd scalar Rsq = e(r2): m1

eststo m2: wildbootstrap regress ind_target previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 0 & monitoring ==1, cluster(unique_group_6) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m2
}
estadd scalar Clusters = e(N_clust): m2
estadd scalar Rsq = e(r2): m2

eststo m3: wildbootstrap regress monitoring_decision previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 0 & monitoring ==1, cluster(unique_group_6) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m3
}
estadd scalar Clusters = e(N_clust): m3
estadd scalar Rsq = e(r2): m3

eststo m4: wildbootstrap regress ifmontwentyfive previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 0 & monitoring ==1, cluster(unique_group_6) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m4
}
estadd scalar Clusters = e(N_clust): m4
estadd scalar Rsq = e(r2): m4

eststo m5: wildbootstrap regress ifmonninety previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 0 & monitoring ==1, cluster(unique_group_6) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m5
}
estadd scalar Clusters = e(N_clust): m5
estadd scalar Rsq = e(r2): m5


esttab m1 m2 m3 m4 m5 using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\learning_regression_bonus.tex", replace cells(b(star pvalue(bootp) fmt(3)) bootll(par("["))&bootul(par(","))&bootend(par("]"))) scalar(Clusters Rsq) ///
substitute (" ]1.000" "]") label collab(none) nonumb drop(_cons) ///
starlevels( * 0.10 ** 0.05 *** 0.010)
 
 
 *individual level outcomes - fine robustness

est clear
eststo m1: wildbootstrap regress dn_applied previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 1 & monitoring ==1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m1
}
estadd scalar Clusters = e(N_clust): m1
estadd scalar Rsq = e(r2): m1

eststo m2: wildbootstrap regress ind_target previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 1 & monitoring ==1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m2
}
estadd scalar Clusters = e(N_clust): m2
estadd scalar Rsq = e(r2): m2

eststo m3: wildbootstrap regress monitoring_decision previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 1 & monitoring ==1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m3
}
estadd scalar Clusters = e(N_clust): m3
estadd scalar Rsq = e(r2): m3

eststo m4: wildbootstrap regress ifmontwentyfive previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 1 & monitoring ==1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m4
}
estadd scalar Clusters = e(N_clust): m4
estadd scalar Rsq = e(r2): m4

eststo m5: wildbootstrap regress ifmonninety previous_others_on_target previous_group_monitor ninety##seq actual_period if fine == 1 & monitoring ==1, cluster(unique_group_12) rseed(12345)
mat bootp= r(table)["pvalue", 1...], .z
mat bootll=r(table)["ll", 1...], .z
mat bootul=r(table)["ul", 1...], .z
mat bootend= J(rowsof(e(b)), colsof(e(b)), 1)
foreach stat in p ll ul end{
    mat colnames boot`stat'= previous_others_on_target previous_group_monitor 1.ninety 1.seq 1.ninety#1.seq actual_period _cons
    estadd mat boot`stat'= boot`stat': m5
}
estadd scalar Clusters = e(N_clust): m5
estadd scalar Rsq = e(r2): m5


esttab m1 m2 m3 m4 m5 using "C:\Users\bjb210\OneDrive - University of Exeter\lab games\analysis\monitoring_homogenous_lab_game_analysis_R\stata_tabs\R2_revision\learning_regression_fine.tex", replace cells(b(star pvalue(bootp) fmt(3)) bootll(par("["))&bootul(par(","))&bootend(par("]"))) scalar(Clusters Rsq) ///
substitute (" ]1.000" "]") label collab(none) nonumb drop(_cons) ///
starlevels( * 0.10 ** 0.05 *** 0.010)



}

